<template>
  <!-- 轮播图 -->
  <div class="carousel">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="value of carouselList" :key="value.imgUrl">
        <img :src="value.imgUrl" alt="" />
      </van-swipe-item>
      <template #indicator="{ active }">
        <div class="custom-indicator">{{ active + 1 }}/3</div>
      </template>
    </van-swipe>
  </div>
</template>

<script>
import { onMounted, computed } from "vue";
import { useStore } from "vuex";
export default {
  setup() {
    const store = useStore();
    const getHeaderCarousel = () => store.dispatch("getHeaderCarousel");
    onMounted(() => getHeaderCarousel());
    // 轮播图列表
    const carouselList = computed(
      () => store.state.loudVoice.getHeaderCarousel.result
    );
    return {
      carouselList,
      getHeaderCarousel,
    };
  },
};
</script>

<style lang="less" scoped>
// 轮播图
.carousel {
  padding: 0 10px;
  margin-bottom: 28px;
  img {
    width: 100%;
    height: 100%;
  }
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  height: 121px;
  text-align: center;
}
.custom-indicator {
  position: absolute;
  left: 5px;
  bottom: 5px;
  padding: 2px 5px;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.1);
}
</style>
